<?php

namespace App\Http\Controllers\App;

use App\Http\Controllers\Controller;
use App\Models\App\AppUser;
use App\Models\Common\ApiResponse;
use App\Models\Common\BaseModel;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class AppUserController extends Controller
{
    public function info(Request $request): array
    {
        $appUser = app_user();

        return ApiResponse::return('', $appUser);
    }

    public function list(Request $request): array
    {
        $more = $request->post();
        $page = intval(Arr::get($more, 'page') ?: 1);
        $perPage = intval(Arr::get($more, 'per_page') ?: 10);

        $queryBuilder = AppUser::query();

        $name = Arr::get($more, 'name');
        if (null !== $name) {
            $queryBuilder->where('name', 'like', '%'.$name.'%');
        }

        if ($phone = Arr::get($more, 'phone')) {
            $queryBuilder->where('phone', 'like', $phone.'%');
        }

        $parkingLots = BaseModel::getList($queryBuilder, $page, $perPage);

        return ApiResponse::return('', $parkingLots);
    }
}
